package loadresource;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import com.example.administrator.weipiao.HttpUtil;

import java.io.IOException;

/**
 * Created by Administrator on 2016/9/10.
 */
public class LoadImgTask extends AsyncTask<String,Void,Bitmap>{
    public interface OnGetImageResultListener{
        void onGetImageResult(Bitmap result);
    }
    private OnGetImageResultListener mListemer;
    public LoadImgTask(OnGetImageResultListener listener){
        this.mListemer = listener;
    }

    @Override
    protected Bitmap doInBackground(String... params) {
        try {
            byte[] data = HttpUtil.loadData(params[0]);
            return BitmapFactory.decodeByteArray(data,0,data.length);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        super.onPostExecute(bitmap);
        if (bitmap!=null&&mListemer!=null){
            mListemer.onGetImageResult(bitmap);
        }
    }
}
